//
//  HRHearCollectionViewCell.m
//  Hear
//
//  Created by mac on 2017/7/6.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRHearCollectionViewCell.h"
#import "HRCoverImageModel.h"
@interface HRHearCollectionViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *nickNameLabel;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UIImageView *remendImageView;
@end
@implementation HRHearCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.iconImageView.layer.cornerRadius = self.iconImageView.width/2;
    self.iconImageView.clipsToBounds = YES;
    
    self.iconImageView.userInteractionEnabled = YES;
    
    WeakSelf
    UITapGestureRecognizer *iconTap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        if (weakSelf.clickIconBlock){
            weakSelf.clickIconBlock();
        }
    }];
    [self.iconImageView addGestureRecognizer:iconTap];
    
    
    UITapGestureRecognizer *nickNameTap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        if (weakSelf.clickIconBlock){
            weakSelf.clickIconBlock();
        }
    }];
    [self.nickNameLabel addGestureRecognizer:nickNameTap];
    
    
    self.remendImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *remendTap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        if (weakSelf.clickNickNameBlock){
            weakSelf.clickNickNameBlock();
        }
    }];
    [self.remendImageView addGestureRecognizer:remendTap];
    self.nickNameLabel.numberOfLines = 2;
    self.nickNameLabel.textColor = FirstTextColor;
    // Initialization code
}


-(void)setModel:(HRMainRootModel *)model{
    
    
    WeakSelf
    
    if ([model.UserPictureBackgroundColor length]){
        [HRCoverImageModel OriginImage:[UIImage imageNamed:model.UserPictureName] scaleToSize:CGSizeMake(75, 75) callBackOriginImage:^(UIImage *originImage) {
            weakSelf.iconImageView.image = originImage;
        }];
        self.iconImageView.backgroundColor = [UIColor colorWithHexString:model.UserPictureBackgroundColor];
    }else{
        [self.iconImageView setImageWithURL:[NSURL URLWithString:model.UserPictureName] placeholder:[UIImage imageNamed:@""]];
    }
    
    if (model.NickName.length){
        self.remendImageView.hidden = NO;
    }else{
        self.remendImageView.hidden = YES;
    }
    
    self.nickNameLabel.text = model.NickName;
}

@end
